<?php

namespace app\admin\controller\user;

use app\common\controller\AdminController;
use EasyAdmin\annotation\ControllerAnnotation;
use EasyAdmin\annotation\NodeAnotation;
use think\App;

/**
 * @ControllerAnnotation(title="用户资产流水")
 */
class AmountLog extends AdminController {

    use \app\admin\traits\Curd;

    public function __construct(App $app) {
        parent::__construct($app);

        $this->model = new \app\admin\model\UserAmountLog();

        $this->assign('getUserList', $this->model->getUserList());

        //获取用户资产流水配置项
        $this->assign('getConfigAmountLogTypes', config('logtype')['amount']);

    }


    /**
     * @NodeAnotation(title="列表")
     */
    public function index() {
        if ($this->request->isAjax()) {
            if (input('selectFields')) {
                return $this->selectList();
            }
            [$page, $limit, $where] = $this->buildTableParames();
            $count           = $this->model->withJoin('user', 'LEFT')->where($where)->count();
            $list            = $this->model->withJoin('user', 'LEFT')->where($where)->page($page, $limit)->order($this->sort)->select();
            //格式化用户资产流水
            $log_type_amount = config('logtype')['amount'];
            foreach ($list as $key => $value) {
                $list[$key]['type_show'] = $log_type_amount[$value['type']];
            }
            $data = [
                'code'  => 0,
                'msg'   => '',
                'count' => $count,
                'data'  => $list,
            ];
            return json($data);
        }
        return $this->fetch();
    }
}